
var cid;
parent.layer.load(2, {shade:0.8});
$(document).ready(function(){
    cid = $(".page-tabs-content",window.parent.document).children(".active").data("cid");
    $("#menuId").val(cid);
    loadBasic(cid);
});
function loadBasic(menuId){
    $.post('/manage/basic/getBasic/'+cid,function(data){
        parent.layer.closeAll('loading');
        if(data.status==1){
            if(data.result){
                $("#basicContent").val(data.result.basicContent);
                $("#editType").val(0);
                CKEDITOR.instances.basicContent.setData($('#basicContent').val());

            }
            else{
                parent.layer.msg(data.msg, {icon: 1});
            }
        }
        else if(data.status==4){
            window.location.href="/manage/nopermission.html";
        }
        else if(data.status==5){
            parent.layer.msg(data.msg, {icon: 1});
            window.location.href="/manage/login.html";
        }
        else{
            parent.layer.msg(data.msg, {icon: 1});
        }
    });
}
CKEDITOR.replace('basicContent');

layui.use(['form'], function(){
    var form = layui.form;

    //自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 2){
                return '标题至少得2个字符啊';
            }
        }
    });

    //监听提交
    form.on('submit(demo1)', function(data){
        //JSON.stringify(data.field)
        updateBasic();
        //alert(CKEDITOR.instances.basicContent.getData());
        return false;
    });
});
function updateBasic(){
    $("#basicContent").val(CKEDITOR.instances.basicContent.getData());
    $.post('/manage/basic/updateBasic/'+cid,$("form").serialize(),function(data){
        if(data.status==1){//登陆成功
            parent.layer.msg(data.msg, {icon: 1});
            loadBasic(cid);
        }
        else if(data.status==4){
            window.location.href="/manage/nopermission.html";
        }
        else if(data.status==5){
            parent.layer.msg(data.msg, {icon: 1});
            window.location.href="/manage/login.html";
        }
        else{
            parent.layer.msg(data.msg, {icon: 1});
        }
    });
}